# $Id$
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=intel-ucode
pkgver=20170707
# Some random "download id" that intel has in their downloadcenter
_dlid=26925
pkgrel=1
pkgdesc="Microcode update files for Intel CPUs"
arch=('any')
install=$pkgname.install
url="https://downloadcenter.intel.com/SearchResult.aspx?lang=eng&keyword=%22microcode%22"
replaces=('microcode_ctl')
license=('custom')
source=("https://downloadmirror.intel.com/${_dlid}/eng/microcode-${pkgver}.tgz"
        'LICENSE'
        'intel-microcode2ucode.c')
sha256sums=('4fd44769bf52a7ac11e90651a307aa6e56ca6e1a814e50d750ba8207973bee93'
            '6983e83ec10c6467fb9101ea496e0443f0574c805907155118e2c9f0bbea97b6'
            '5af76d7e23768c94ab03fbf0d280b30fccd9c1ce697111c9999f6d51955c5a98');

build() {
  cd "$srcdir"

  gcc -Wall ${CFLAGS} -o intel-microcode2ucode intel-microcode2ucode.c

  ./intel-microcode2ucode ./microcode.dat
}

package() {
  cd "$srcdir"

  install -d -m755 "${pkgdir}"/boot

  mkdir -p kernel/x86/microcode
  mv microcode.bin kernel/x86/microcode/GenuineIntel.bin
  echo kernel/x86/microcode/GenuineIntel.bin | bsdcpio -o -H newc -R 0:0 > "${pkgdir}"/boot/intel-ucode.img

  install -D -m644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
